/**
 * 
 */
package com.helper;

import java.util.List;

import com.photomap.UI.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * @author cheng
 *
 */
public class PhotoItemAdapter extends BaseAdapter {

	private Context context;
	private List<PhotoItem> list;
	public PhotoItemAdapter(Context ct,List<PhotoItem> list)
	{
		context = ct;
		this.list = list;
	}
	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		if (position < list.size()) {
			return list.get(position);
			} else {
			return null;
			}
		}

	public long getItemId(int position) {
		if (position < list.size()) {
			return list.get(position).getId();
			} else {
			return -1;
			}
		}

	public View getView(int position, View convertView, ViewGroup parent) {
		PhotoItem item = list.get(position);
		LayoutInflater mInflater = LayoutInflater.from(context);
		View view;
		if (convertView != null && convertView.getId() == R.id.List1) {
		view = convertView;
		} else {
		view = mInflater.inflate(R.layout.index_item_listview, parent, false);
		}
		ItemViewHolder holder = (ItemViewHolder) view.getTag();
		if (holder == null) {
			holder = new ItemViewHolder();
			holder.myImageView = (ImageView) view.findViewById(R.id.img);
			holder.nameTextView = (TextView) view.findViewById(R.id.name);
			holder.myBt = (TextView) view.findViewById(R.id.bt1);
			holder.infoTextView = (TextView) view.findViewById(R.id.info);
			view.setTag(holder);
		}
		if (item != null) {
			
			if(item.getBitMap() != null)
			{
				holder.myImageView.setImageBitmap(item.getBitMap());
			}
			else
			{
				System.out.print("set ImageRes and resId = "+item.getIcon());
				holder.myImageView.setImageResource(item.getIcon());
			}
			holder.nameTextView.setText(item.getName());
			holder.myBt.setText(item.getButton());
			holder.infoTextView.setText(item.getInfo());
		}
		return view;
		}

	protected class ItemViewHolder {
		public ImageView myImageView;
		public TextView nameTextView;
		public TextView myBt ;
		public TextView infoTextView;
		}
}

